﻿@page "/employeeedit/{DepartmentId}"
@page "/employeeedit/{DepartmentId}/{EmployeeId}"
@using Covid.Shared.Dtos

<h3>Employee Edit</h3>

@if (!Saved)
{
    <EditForm Model="@Employee"
              OnValidSubmit="@HandleValidSubmit"
              OnInvalidSubmit="@HandleInvalidSubmit">
        <DataAnnotationsValidator />
        <ValidationSummary></ValidationSummary>
        <div class="form-group row">
            <label for="no" class="col-sm-2 col-form-label">编号</label>
            <div class="col-sm-10">
                <InputText class="form-control" id="no" @bind-Value="@Employee.No"/>
                <ValidationMessage For="@(() => Employee.No)" />
            </div>
        </div>
        <div class="form-group row">
            <label for="name" class="col-sm-2 col-form-label">姓名</label>
            <div class="col-sm-10">
                <InputText class="form-control" id="name" @bind-Value="@Employee.Name"/>
                <ValidationMessage For="@(() => Employee.Name)" />
            </div>
        </div>
        <div class="form-group row">
            <label for="birthDate" class="col-sm-2 col-form-label">出生日期</label>
            <div class="col-sm-10">
                <InputDate class="form-control" id="birthDate" @bind-Value="@Employee.BirthDate"/>
            </div>
        </div>
        <div class="form-group row">
            <label for="gender" class="col-sm-2 col-form-label">性别</label>
            <div class="col-sm-10">
                <InputSelect class="form-control" id="gender" @bind-Value="@Employee.Gender">
                    @foreach (var value in Enum.GetValues(typeof(Gender)))
                        {
                        <option value="@value">@value</option>
                        }
                </InputSelect>
            </div>
        </div>

        <div class="form-group row">
            <label for="departmentId" class="col-sm-2 col-form-label">部门</label>
            <div class="col-sm-10">
                <InputSelect class="form-control" id="departmentId" @bind-Value="@EmployeeDepartmentId">
                    @foreach (var department in Departments)
                        {
                        <option value="@department.Id">@department.Name</option>
                        }
                </InputSelect>
            </div>
        </div>


        <div class="form-group row offset-sm-2">
            @if (!string.IsNullOrWhiteSpace(EmployeeId))
            {
                <button class="btn btn-danger mr-2" @onclick="@DeleteEmployee">Delete</button>
            }

            <button type="submit" class="btn btn-primary mr-2">Submit</button>
            <button class="btn btn-secondary" @onclick="@GoBack">Go Back</button>
        </div>

    </EditForm>

}
else
{
    <div class="@CssClass" role="alert">
        @Message
    </div>
}